<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>高度塌陷</title>
  <style>
    .box1 {
      width: 500px;
      /* height: 200px; */
      border: 10px solid red;
    }
    .box2 {
      width: 100px;
      height: 100px;
      background-color: #abf;
      float: right;
    }
    .clearfix::before,
    .clearfix::after{
      content: "";
      display: table;
      clear: both;  /* 元素左右两侧均不允许出现浮动元素 */
    }
  </style>
</head>
<body>
  <div class="box1 clearfix">
    <div class="box2"></div>
  </div>
</body>
</html>